package com.xujc.entity;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.context.annotation.Lazy;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Collection;

/**
 * Created by xujc on 6/16/15.
 */
@Entity
@Table(name = "form", schema = "", catalog = "test")
@DynamicInsert(true)
@DynamicUpdate(true)
@Lazy(value = false)
public class FormEntity {
    private int mFId;
    private String mName;
    private int mDiscuseNumber;
    private String mFormDescribe;
    private Timestamp mLastActive;
    private Collection<DiscuseEntity> mDiscusesByFId;

    @Id
    @Column(name = "f_id")
    @GeneratedValue
    public int getFId() {
        return mFId;
    }

    public void setFId(int FId) {
        mFId = FId;
    }

    @Basic
    @Column(name = "name")
    public String getName() {
        return mName;
    }

    public void setName(String name) {
        mName = name;
    }

    @Basic
    @Column(name = "discuse_number")
    public int getDiscuseNumber() {
        return mDiscuseNumber;
    }

    public void setDiscuseNumber(int discuseNumber) {
        mDiscuseNumber = discuseNumber;
    }

    @Basic
    @Column(name = "form_describe")
    public String getFormDescribe() {
        return mFormDescribe;
    }

    public void setFormDescribe(String formDescribe) {
        mFormDescribe = formDescribe;
    }

    @Basic
    @Column(name = "last_active")
    public Timestamp getLastActive() {
        return mLastActive;
    }

    public void setLastActive(Timestamp lastActive) {
        mLastActive = lastActive;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        FormEntity that = (FormEntity) o;

        if (mDiscuseNumber != that.mDiscuseNumber) return false;
        if (mFormDescribe != that.mFormDescribe) return false;
        if (mName != null ? !mName.equals(that.mName) : that.mName != null) return false;
        if (mLastActive != null ? !mLastActive.equals(that.mLastActive) : that.mLastActive != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = mName != null ? mName.hashCode() : 0;
        result = 31 * result + mDiscuseNumber;
        result = 31 * result + (mName != null ? mName.hashCode() : 0);
        result = 31 * result + (mLastActive != null ? mLastActive.hashCode() : 0);
        return result;
    }

    @OneToMany(mappedBy = "formByFId",fetch = FetchType.EAGER)
    @Lazy(value = false)
    public Collection<DiscuseEntity> getDiscusesByFId() {
        return mDiscusesByFId;
    }

    public void setDiscusesByFId(Collection<DiscuseEntity> discusesByFId) {
        mDiscusesByFId = discusesByFId;
    }
}
